package com.cman777.springc.ratelimiter.alg.storage;

import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.concurrent.TimeUnit;

/**
 * @author chenzhicong
 * @time 2020/9/18 11:33
 */
@AllArgsConstructor
public class RedisTemplateStorageAdapter implements RedisStorage{
    private RedisTemplate redisTemplate;

    @Override
    public Long incrementAndGet(String key) {
        return redisTemplate.opsForValue().increment(key);
    }

    @Override
    public boolean setIfAbsent(String key, Long value, Long time, TimeUnit timeUnit) {
        return redisTemplate.opsForValue().setIfAbsent(key,value,time,timeUnit);
    }

    @Override
    public boolean expire(String key, long unit, TimeUnit timeUnit) {
        return redisTemplate.expire(key,unit,timeUnit);
    }
}
